#include <bits/stdc++.h>
using namespace std;
#define int long long
// char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
// #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
    return x*f;
}
const int N=5e5+4,K=6e6;
struct gg{
    int x,y;
    gg zz(){
        int z=abs(__gcd(x,y));
        return {x/z,y/z};
    }
    gg operator +(const gg &b)const{
        gg c={x*b.y+b.x*y,y*b.y};
        return c;
    }
    bool operator <(const gg &b)const{
        return x*b.y<b.x*y;
    }
    bool operator ==(const gg &b)const{
        return x*b.y==b.x*y;
    }
};
int n,a[N],s[N],maxx[N],nx[N];
mt19937 rnd(147744151);
int z[N],id[N],top,cnt,ccnt;
struct qu{
    int l,r;
    gg v;
}b[K];
void cl(){
    z[top=1]=1e9;
    id[top]=n+1;
    for(int i=n;i>=1;i--){
        while(s[i]>=z[top]) top--;
        nx[i]=id[top];
        z[++top]=s[i];
        id[top]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j=nx[j]){
            if(j-i>sqrt(n)) break;
            b[++cnt]={i,j,{(s[j]-s[i-1])*(s[j]-s[i-1]),j-i+1}};
        }
    }
}
gg bl(){
    gg ans={0,1};
    z[top=1]=1e9;
    id[top]=n+1;
    for(int i=n;i>=1;i--){
        while(s[i]>=z[top]) top--;
        nx[i]=id[top];
        z[++top]=s[i];
        id[top]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j=nx[j]){
            gg c={(s[j]-s[i-1])*s[j]-s[i-1],j-i+1};
            ans=max(ans,c);
        }
    }
    return ans;
}
int ran(){
    return 1001ll-((rnd()+2001ll)%(2001ll));
}
#define lowbit(x) (x&-x)
gg t[N];
void add(int x,gg v){
    while(x) t[x]=max(t[x],v),x-=lowbit(x);
}
gg ask(int x){
    gg ans={0,1};
    while(x<=n) ans=max(ans,t[x]),x+=lowbit(x);
    return ans;
}
int Q;
struct query{
    int l,r,id;
}q[N];
gg ans[N];
bool cmp(query a,query b){
    if(a.id==0) exit(0);
    return a.r>b.r;
}
signed main(){
    // freopen("value.in","r",stdin);
    // freopen("value.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++) t[i]={0,1};
    for(int i=1;i<=n;i++) a[i]=read();
    // for(int i=1;i<=n;i++) cerr<<a[i]<<" ";
    for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
    cl();
    for(int i=1;i<=n;i++) s[i]=s[i-1]-a[i];
    cl();
    sort(b+1,b+cnt+1,[](qu a,qu b){return a.r<b.r;});
    // for(int i=1;i<=cnt;i++) cerr<<b[i].l<<" "<<b[i].r<<" "<<b[i].v.x<<" "<<b[i].v.y<<"\n";
    Q=read();
    for(int i=1;i<=Q;i++) q[i].l=read(),q[i].r=read(),q[i].id=i;
    sort(q+1,q+Q+1,cmp);
    int now=1;
    for(int i=1;i<=Q;i++){
        while(now<=cnt&&b[now].r<=q[i].r) add(b[now].l,b[now].v),now++;
        // cerr<<q[i].l<<" "<<q[i].r<<" "<<now<<"\n";
        ans[q[i].id]=ask(q[i].l);
    }
    for(int i=1;i<=Q;i++){
        gg z=ans[i].zz();
        cout<<z.x<<" "<<z.y<<"\n";
    }
    return 0;
}